package com.leyou.search.controller;

import com.leyou.search.service.impl.SearchServiceImpl;
import com.leyou.search.utils.SearchRequest;
import com.leyou.search.utils.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author: Saka
 * Date: 2019/2/13
 * Time: 20:19
 */
@RestController
public class SearchController {

    @Autowired
    private SearchServiceImpl searchService;



    @PostMapping("page")
    public ResponseEntity<SearchResult> search(@RequestBody SearchRequest searchRequest) {
        SearchResult searchResult = this.searchService.query(searchRequest);
        if (searchResult != null && null != searchResult.getItems() && 0 != searchResult.getItems().size()) {
            return ResponseEntity.ok(searchResult);
        }
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }



}
